package org.shagin.jfin.ui.date.cond;

import javax.swing.JPanel;
import javax.swing.event.EventListenerList;

import org.shagin.jfin.core.CoreUtils;
import org.shagin.jfin.date.cond.IDateCondition;

/**
 * The Class DateConditionPane.
 * 
 * @param <T> the generic type
 */
@SuppressWarnings("serial")
public class DateConditionPane<T extends IDateCondition> extends JPanel {

    protected EventListenerList listenerList = new EventListenerList();
    protected IDateCondition dateCondition;

    /**
     * Gets the date condition.
     * 
     * @return the date condition
     */
    public IDateCondition getDateCondition() {
        CoreUtils.checkNotNull(dateCondition, "dateCondition");
        return dateCondition;
    }

    /**
     * Sets the date condition.
     * 
     * @param dateCondition the new date condition
     */
    public void setDateCondition(IDateCondition dateCondition) {
        this.dateCondition = dateCondition;
    }

    /**
     * Gets the title.
     * 
     * @return the title
     */
    public String getTitle() {
        return getDateCondition().getClass().getSimpleName();
    }

    /**
     * Adds the date condition listener.
     * 
     * @param l the l
     */
    public void addDateConditionListener(DateConditionListener l) {
        listenerList.add(DateConditionListener.class, l);
    }

    /**
     * Removes the date condition listener.
     * 
     * @param l the l
     */
    public void removeDateConditionListener(DateConditionListener l) {
        listenerList.remove(DateConditionListener.class, l);
    }

    /**
     * Fire changed event.
     */
    public void fireChangedEvent() {
        DateConditionEvent event = new DateConditionEvent(this,
                getDateCondition());
        for (DateConditionListener l : listenerList
                .getListeners(DateConditionListener.class)) {
            l.dateConditionChanged(event);

        }
    }

    /**
     * Gets the value.
     * 
     * @return the value
     */
    public T getValue() {
        CoreUtils.notImplemented();
        return null;
    }
}
